

var app = getApp();
var page = 1;
var selectedNews = false;
var newsList = [];

Page({
  data: {
    listdefault: 1,
    addresslist: [],
  },
  getList: function () {
    var that = this;
    var url = '/agent/log';
    var params = {
      uid: app.globalData.userInfo.id,
      pageNo: page,
      pageSize: 20
    };
    app.HttpPostSend(url, params, function (res) {
      if (res.msg != "success") {
        app.showTipMsg(res.msg);
        selectedNews = false;
        that.setData({
          addresslist: []
        })
      } else {
        var cardlist = res.data;
        for (var i = 0; i < cardlist.length; i++) {
          cardlist[i].add_time = cardlist[i].send_time;
          if (cardlist[i].status == 1) {
            cardlist[i].status = "已打账";
          } else {
            cardlist[i].status = "未打账";
          }
          newsList.push(cardlist[i]);
        }
        if (cardlist.length < 20) {
          selectedNews = false;
        } else {
          selectedNews = true;
          page += 1;
        }
        that.setData({
          addresslist: newsList
        })
        wx.hideLoading();
      }
    });
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    page = 1;
    selectedNews = false;
    newsList = [];
    this.getList();
  },

  timestampToTime: function (timestamp) {
    var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + "";
    var h = date.getHours() + ':';
    var m = date.getMinutes();
    if (String(m).length == 1) {
      m = "0" + m;
    }
    var s = date.getSeconds();
    return Y + M + D + " " + h + m;
  },//转化后格式xxxx-xx-xx,

  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  // onShareAppMessage: function () {
  //   return {
  //     title: '万商',
  //     desc: '你要的名片代',
  //     path: '/pages/home/home'
  //   }
  // },
  /** 
   * 页面上拉触底事件的处理函数 
   */
  onReachBottom: function () {
    if (selectedNews == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      that.getList();

    } else {
      wx.hideLoading();
    }
  }
})